﻿@Styles.Render("~/Content/fileUpload")
@Scripts.Render("~/bundles/fileupload")
<div class="hidden">
    <input id="fileupload" type="file" name="files[]" multiple>
</div>
<script type="text/javascript">
    /*
    调用参数说明：
    fileInputID：文件域ID
    uploadUrl：上传地址。
    第一步：在视图中添加HYBY.WebFrameWork.Mvc和System.Web命名空间的引用    
    第二步：调用Url.ImageUpload生成上传地址"@@Html.Raw(Url.ImageUpload("201605100001", new String[] { "800*800", "800*600", "400*300" }))";
    succeed：图片上传成功后的回调函数
    failed： 图片上传失败后的回调函数
    progress:图片上传进度回调函数
    */
    function fileUpload(fileInputID, uploadUrl, succeed, failed, progress) {
        $('#fileupload').fileupload({
            url: uploadUrl,
            dataType: 'json',
            autoUpload: true,
            acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
            maxFileSize: 999000
        }).on('fileuploadadd', function (e, data) {
           console.log(data)
        }).on('fileuploadprocessalways', function (e, data) {
        }).on('fileuploadprogressall', function (e, data) {
        }).on("fileuploadprogress", function (e, data) {
            if (progress != undefined) progress(data)
        }).on('fileuploaddone', function (e, data) {
            if (succeed != undefined) succeed(data)
        }).on('fileuploadfail', function (e, data) {
            if (failed != undefined) failed(data)
        })
        var fileInput = document.getElementById(fileInputID);
        var filesList = fileInput.files;
        $('#fileupload').fileupload("add", { files: filesList });
    }
</script>